package com.github.elliot.gatewaycenter.domain;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;


/**
 * @author wwcc
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AdminUserPO implements UserDetails {

    private String userNo;

    private String mobile;

    private String verificationCode;

    private String host;

    private Set<String> backendUrls;

    private String username;

    private String mail;

    private String password;

    private Integer status;

    public AdminUserPO(String username) {
        this.username = username;
    }

    public AdminUserPO(String username, String verificationCode, String host) {
        this.username = username;
        this.verificationCode = verificationCode;
        this.host = host;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Optional.ofNullable(backendUrls)
                .orElse(Collections.emptySet())
                .stream()
                .map(SimpleGrantedAuthority::new)
                .collect(Collectors.toList());
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }

}
